package UtilsApplication;

public class Complex {
    private double re;
    private double im;

    public Complex(double real, double imag) {
        re = real;
        im = imag;
    }

    public double abs()   { 
        return Math.sqrt( re * re + im*im ); 
    }
    public double phase() { 
        return Math.atan2(im, re); 
    }

    public Complex plus(Complex b) {
        Complex a = this;
        double real = a.re + b.re;
        double imag = a.im + b.im;
        return new Complex(real, imag);
    }

    public Complex minus(Complex b) {
        Complex a = this;
        double real = a.re - b.re;
        double imag = a.im - b.im;
        return new Complex(real, imag);
    }

    public Complex times(Complex b) {
        Complex a = this;
        double real = a.re * b.re - a.im * b.im;
        double imag = a.re * b.im + a.im * b.re;
        return new Complex(real, imag);
    }

    public Complex times(double alpha) {
        return new Complex(alpha * re, alpha * im);
    }

    // zwraca sprzezenie
    public Complex conjugate() {  return new Complex(re, -im); }


    public double re() { 
        return re; 
    }
    public double im() { 
        return im; 
    }

    public void addReal( double r ) {
        this.re += r;
    } // addReal

    public void addImag( double j ) {
        this.im += j;
    } // addImag

    public void mulReal( double s ) {
        this.re *= s;
    } // mulReal

    public void mulImag( double s ) {
        this.im *= s;
    } // mulImag
}

